using System;
using System.Collections.Generic;
using System.IO;
using Common;
using Common.NotifyEvent;

namespace SExperiment
{
	[Serializable]
	public class TargetStdCurve : NotifyPropertyChanged
	{
		public string TargetName { get; set; }

		public List<Dot> StdDot { get; set; }

		public double Slope { get; set; }

		public double Intercept { get; set; }

		public double r_Value { get; set; }

		public double Efficiency { get; set; }

		public List<int> StdDotWellNo { get; set; }

		public TargetStdCurve()
		{
			StdDotWellNo = new List<int>();
		}

		public void SaveToStream(StreamEx stream)
		{
			stream.Write(PropertyKey.Key_TargetStdCurve);
			List<PropertyKey> list = new List<PropertyKey>();
			List<byte[]> list2 = new List<byte[]>();
			if (!string.IsNullOrEmpty(TargetName))
			{
				list.Add(PropertyKey.Key_TargetName);
				list2.Add(BytesConverter.GetBytes(TargetName));
			}
			list.Add(PropertyKey.Key_Slope);
			list2.Add(BytesConverter.GetBytes(Slope));
			list.Add(PropertyKey.Key_Intercept);
			list2.Add(BytesConverter.GetBytes(Intercept));
			list.Add(PropertyKey.Key_r_Value);
			list2.Add(BytesConverter.GetBytes(r_Value));
			list.Add(PropertyKey.Key_Efficiency);
			list2.Add(BytesConverter.GetBytes(Efficiency));
			if (StdDot != null)
			{
				list.Add(PropertyKey.Key_StdDot);
				StreamEx streamEx = new StreamEx();
				streamEx.Write(StdDot.Count);
				foreach (Dot item in StdDot)
				{
					streamEx.Write(item.X);
					streamEx.Write(item.Y);
				}
				list2.Add(streamEx.ToArray());
				streamEx.Close();
			}
			stream.Write(PropertyKey.Key_Index);
			stream.WriteIndex(list, list2);
			stream.Flush();
		}

		public bool ReadFromStream(StreamEx stream)
		{
			PropertyKey propertyKey = stream.ReadKey();
			if (propertyKey == PropertyKey.Key_TargetStdCurve)
			{
				propertyKey = stream.ReadKey();
				if (propertyKey == PropertyKey.Key_Index)
				{
					List<PropertyKey> keys;
					List<byte[]> dates;
					stream.ReadIndex(out keys, out dates);
					for (int i = 0; i < keys.Count; i++)
					{
						switch (keys[i])
						{
						case PropertyKey.Key_TargetName:
							TargetName = BytesConverter.BytesToString(dates[i]);
							break;
						case PropertyKey.Key_Slope:
							Slope = BytesConverter.BytesToDouble(dates[i]);
							break;
						case PropertyKey.Key_Intercept:
							Intercept = BytesConverter.BytesToDouble(dates[i]);
							break;
						case PropertyKey.Key_r_Value:
							r_Value = BytesConverter.BytesToDouble(dates[i]);
							break;
						case PropertyKey.Key_Efficiency:
							Efficiency = BytesConverter.BytesToDouble(dates[i]);
							break;
						case PropertyKey.Key_StdDot:
						{
							StreamEx streamEx = new StreamEx();
							streamEx.Write(dates[i]);
							streamEx.Seek(0L, SeekOrigin.Begin);
							StdDot = new List<Dot>();
							int num = streamEx.ReadInt();
							for (int j = 0; j < num; j++)
							{
								Dot dot = new Dot();
								dot.X = streamEx.ReadDouble();
								dot.Y = streamEx.ReadDouble();
								StdDot.Add(dot);
							}
							streamEx.Close();
							break;
						}
						}
					}
					return true;
				}
				stream.Seek(-4L, SeekOrigin.Current);
				return false;
			}
			stream.Seek(-4L, SeekOrigin.Current);
			bool flag = false;
			while (true)
			{
				switch (stream.ReadKey())
				{
				case PropertyKey.Key_TargetName:
					if (flag)
					{
						stream.Seek(-4L, SeekOrigin.Current);
						return true;
					}
					flag = true;
					TargetName = stream.ReadString();
					break;
				case PropertyKey.Key_Slope:
					Slope = stream.ReadDouble();
					break;
				case PropertyKey.Key_Intercept:
					Intercept = stream.ReadDouble();
					break;
				case PropertyKey.Key_r_Value:
					r_Value = stream.ReadDouble();
					break;
				case PropertyKey.Key_Efficiency:
					Efficiency = stream.ReadDouble();
					break;
				case PropertyKey.Key_StdDot:
				{
					StdDot = new List<Dot>();
					int num2 = stream.ReadInt();
					for (int k = 0; k < num2; k++)
					{
						Dot dot2 = new Dot();
						dot2.X = stream.ReadDouble();
						dot2.Y = stream.ReadDouble();
						StdDot.Add(dot2);
					}
					break;
				}
				default:
					stream.Seek(-4L, SeekOrigin.Current);
					return true;
				}
			}
		}
	}
}
